<script type="text/javascript">
function setMail() {
	if ($("input[type=radio][name=method][checked]").val() == "smtp") {
    	if (isNull("smtpserver")) {
    		$("#msgMail").text("<?= $this->translate('message.common.validate.null')?>");
    		return false;
    	}
    	if (isNull("smtpport")) {
    		$("#msgMail").text("<?= $this->translate('message.common.validate.null')?>");
    		return false;
    	}
    	if (! isNumber("smtpport")) {
    		$("#msgMail").text("<?= $this->translate('message.common.validate.number')?>");
    		return false;
    	}
	}
	if (isNull("sender")) {
		$("#msgMail").text("<?= $this->translate('message.common.validate.null')?>");
		return false;
	}
	var url = "<?= Zend_Registry::get('baseUrl')?>/admin/mail/setmail";
	var param = "method=" + $("input[type=radio][name=method][checked]").val();
		param += "&sender=" + $.trim($("#sender").val());
		param += "&signature=" + $.trim($("#signature").val());
		param += "&smtpserver=" + $.trim($("#smtpserver").val());
		param += "&smtpport=" + $.trim($("#smtpport").val());
		param += "&smtpusername=" + $.trim($("#smtpusername").val());
		param += "&smtppassword=" + $.trim($("#smtppassword").val());
	$.post(url, param, function(data) {
		if (data == "successful") {
			$("#msgMail").text("<?= $this->translate('message.common.successful')?>");
		}
		else
			$("#msgMail").text("<?= $this->translate('message.common.failed')?>");
	});
}
function testMail() {
	if (isNull("recipient")) {
		$("#msgMailTest").text("<?= $this->translate('message.common.validate.null')?>");
		return false;
	}
	if (isNull("content")) {
		$("#msgMailTest").text("<?= $this->translate('message.common.validate.null')?>");
		return false;
	}
	var url = "<?= Zend_Registry::get('baseUrl')?>/admin/mail/testmail";
	var param = "recipient=" + $.trim($("#recipient").val());
		param += "&content=" + replaceAmp($.trim($("#content").val()));
	$.post(url, param, function(data) {
		if (data == "successful") {
			$("#msgMailTest").text("<?= $this->translate('message.common.successful')?>");
		}
		else
			$("#msgMailTest").text("<?= $this->translate('message.common.failed')?>");
	});
}

function disableSMTP(flag) {
	$('#smtpserver').attr('disabled', flag);
	$('#smtpport').attr('disabled', flag);
	$('#smtpusername').attr('disabled', flag);
	$('#smtppassword').attr('disabled', flag);
}
</script>
<br />
<table class="table-admin" align="center">
<thead class="bottomhr">
<tr>
    <td colspan="2"><?= $this->translate('admin.mail.method.title')?></td>
</tr>
</thead>
<tbody>
<tr>
	<td colspan="2"><input type="radio" class="radio" value="phpmail" name="method" <?php if (Zend_Registry::get('config')->mail->method == "phpmail") echo 'checked="checked"'?> onclick="disableSMTP(true)" />&nbsp;<?= $this->translate('admin.mail.method.phpmail')?></td>
</tr>
<tr>
	<td colspan="2"><input type="radio" class="radio" value="smtp" name="method" <?php if (Zend_Registry::get('config')->mail->method == "smtp") echo 'checked="checked"'?> onclick="disableSMTP(false)" />&nbsp;<?= $this->translate('admin.mail.method.smtp')?></td>
</tr>
<tr>
<td colspan="2">
    <table class="table-embedded">
    <tbody>
        <tr>
        	<td width="20%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?= $this->translate('admin.mail.smtp.server')?>:</td>
        	<td width="80%"><input type="text" id="smtpserver" value="<?= Zend_Registry::get('config')->smtp->server?>" class="middle" /></td>
        </tr>
        <tr>
        	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?= $this->translate('admin.mail.smtp.port')?>:</td>
        	<td><input type="text" id="smtpport" value="<?= Zend_Registry::get('config')->smtp->port?>" class="middle"/></td>
        </tr>
        <tr>
        	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?= $this->translate('admin.mail.smtp.username')?>:</td>
        	<td><input type="text" id="smtpusername" value="<?= Zend_Registry::get('config')->smtp->username?>" class="middle"/></td>
        </tr>
        <tr>
        	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?= $this->translate('admin.mail.smtp.password')?>:</td>
        	<td><input type="password" id="smtppassword" value="<?= Zend_Registry::get('config')->smtp->password?>" class="middle"/></td>
        </tr>
    </tbody>
    </table>
</td>
</tr>
</tbody>
<thead class="tophr">
<tr>
	<td colspan="2"><?= $this->translate('admin.mail.sender.title')?></td>
</tr>
</thead>
<tbody>
<tr>
	<td width="19%"><?= $this->translate('admin.mail.sender.email')?>:</td>
	<td width="81%"><input type="text" id="sender" class="middle" value="<?= Zend_Registry::get('config')->mail->sender?>" /></td>
</tr>
<tr>
	<td><?= $this->translate('admin.mail.sender.signature')?>:</td>
	<td><input type="text" id="signature" class="middle" value="<?= Zend_Registry::get('config')->mail->signature?>" /></td>
</tr>
<tr>
	<td><input type="button" onclick="setMail()" value="<?= $this->translate('common.button.ok')?>" /></td>
	<td><span id="msgMail" class="message" /></td>
</tr>
</tbody>
<thead class="tophr">
<tr>
	<td colspan="2"><?= $this->translate('admin.mail.test.title')?></td>
</tr>
</thead>
<tbody>
<tr>
	<td><?= $this->translate('admin.mail.test.recipient')?>:</td>
	<td>
		<input type="text" id="recipient" class="middle" />&nbsp;&nbsp;&nbsp;&nbsp;
		<?= $this->translate('admin.mail.test.tip')?>
	</td>
</tr>
<tr>
	<td><?= $this->translate('admin.mail.test.content')?>:</td>
	<td><textarea id="content" class="middle"></textarea>&nbsp;&nbsp;&nbsp;&nbsp;
		<?= $this->translate('admin.mail.test.html')?>
	</td>
</tr>
<tr>
	<td><input type="button" onclick="testMail()" value="<?= $this->translate('common.button.ok')?>" /></td>
	<td><span id="msgMailTest" class="message" /></td>
</tr>
</tbody>
</table>
<div class="content-bottom" />